package com.woniuxy.tfss.jwt;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.tfss.entity.Perms;
import com.woniuxy.tfss.service.PermsService;
import com.woniuxy.tfss.web.Quartz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class PermsMapFactoryBean implements FactoryBean<Map<String, String>> {
    @Autowired
    private PermsService permsService;

    @Override
    public Map<String, String> getObject()  {

        Map<String, String> map = new LinkedHashMap<>();
        map.put("/admin/login","anon");
        map.put("/admin/getMenuById","jwt");
        map.put("/admin/changePwd","jwt");

        QueryWrapper<Perms> wrapper=new QueryWrapper<>();
        wrapper.eq("type","a");
        List<Perms> perms=permsService.list(wrapper);
        perms.forEach(d->{
           map.put( d.getLink(), "jwt,perms[" + d.getIdentity() + "]");
          log.debug("获取所有权限：{}---{}", d.getLink(), d.getIdentity());
       });


        map.put("/**","anon");
        return map;
    }

    @Override
    public Class<?> getObjectType() {
        return Map.class;
    }
}
